package com.example.food.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.AjaxResult;
import com.example.food.domain.Goods;
import com.example.food.mapper.FoodMapper;
import com.example.food.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.Objects;

@Service
public class FoodServiceImpl  extends ServiceImpl<FoodMapper, Goods>  implements FoodService {

    @Autowired
    private FoodMapper foodMapper;

    @Override
    public AjaxResult selectList(Goods goods) {
        LambdaQueryWrapper<Goods> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Objects.nonNull(goods.getName()),Goods::getName,goods.getName());
        foodMapper.selectList(wrapper);
        return AjaxResult.success().put("data", foodMapper.selectList(wrapper));
    }

    @Override
    public AjaxResult addOther(Goods g) {
        LambdaQueryWrapper<Goods> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Goods::getName,g.getName());
        Goods g1 = foodMapper.selectOne(wrapper);
        if(!Objects.isNull(g1)){
            return AjaxResult.error("该奶茶已存在");
        }
        foodMapper.insert(g);
        return AjaxResult.success("新增成功");
    }

}
